from function import function_help


class DataPreQuery(object):
    fun_tool = function_help.Function_Help()
    mysql_connect_info = fun_tool.get_yaml_info()['info']['mysql_saas_shyd_info']

    def query_user_permission(self, user):
        result = True
        # 查看用户的所有角色信息
        sql00 = f"""
                select iur.code from iam_uc_account iua
                left join iam_uc_account_role_r iuarr on iua.code = iuarr.account_code
                left join iam_uc_role iur on iuarr.role_code = iur.code
                where iua.login_name = '{user}' and iuarr.deleted = 0;
                """
        result00 = self.fun_tool.conn_mysql(sql00, self.mysql_connect_info)
        # 获取系统管理员的角色信息
        sql01 = """
                select value from base_fundamental_data where catalog = 'role_info'
                """
        result01 = self.fun_tool.conn_mysql(sql01, self.mysql_connect_info)
        for i in range(len(result00)):
            if str(result00[i]['code']) == result01[0]['value']:
                break
        else:
            result = False
        return result


if __name__ == '__main__':
    test = DataPreQuery().query_user_permission('sysadmin')
    print(test)
